package com.yanqu.road.server.cmd.estatewar.activity;

import com.yanqu.road.entity.enums.eSystemId;
import com.yanqu.road.pb.estatewar.EstateWarProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.config.SystemOpenMgr;
import com.yanqu.road.server.manger.palace.PalaceActivity;
import com.yanqu.road.server.manger.palace.PalaceActivityMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_PALACE_FLOOR_LIST, desc = "皇宫位置列表获取")
public class GetPalaceFloorListCmd extends AbstractCommand {
    private int activityId;
    private int pageNum;
    private long time;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        EstateWarProto.PalaceFloorListReqMsg reqMsg = EstateWarProto.PalaceFloorListReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        pageNum = reqMsg.getPageNum();
        time = reqMsg.getTime();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        PalaceActivity palaceActivity = PalaceActivityMgr.getPalaceActivity(activityId);
        if(null == palaceActivity){
            ret = GameErrorCode.E_PALACE_ACTIVITY_NO_FOUND;
            return;
        }
        if(!SystemOpenMgr.systemOpen(player, eSystemId.PalaceActivity.getValue())){
            ret = GameErrorCode.E_SYSTEM_NO_OPEN;
            return;
        }
        //发送到跨服获取
        EstateWarProto.PalaceFloorListReqMsg.Builder crossMsg = EstateWarProto.PalaceFloorListReqMsg.newBuilder();
        crossMsg.setActivityId(activityId);
        crossMsg.setPageNum(pageNum);
        crossMsg.setTime(time);
        YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(Protocol.C_PALACE_FLOOR_LIST, crossMsg);
        GamePlayerMgr.sendPacket(player.getUserId(), pbMsg);
    }

    @Override
    public void sendData(GamePlayer player) {
        if(0 != ret) {
            EstateWarProto.PalaceFloorListRespMsg.Builder respMsg = EstateWarProto.PalaceFloorListRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(Protocol.U_PALACE_FLOOR_LIST, respMsg);
        }
    }
}
